import { ref } from 'vue'

const messageState = ref({
  show: false,
  message: '',
  type: 'info',
  duration: 3000
})

export function useMessage() {
  const showMessage = (message, type = 'info', duration = 3000) => {
    messageState.value = {
      show: true,
      message,
      type,
      duration
    }
  }

  const hideMessage = () => {
    messageState.value.show = false
  }

  const success = (message, duration) => showMessage(message, 'success', duration)
  const error = (message, duration) => showMessage(message, 'error', duration)
  const warning = (message, duration) => showMessage(message, 'warning', duration)
  const info = (message, duration) => showMessage(message, 'info', duration)

  return {
    messageState,
    showMessage,
    hideMessage,
    success,
    error,
    warning,
    info
  }
}
